﻿Public Class MeuCadastroAdm
    Inherits System.Web.UI.Page
    Dim admLogado As New Adm

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("AdmLogado") Is Nothing Then
            Response.Redirect("/Screens/WF1.aspx")
        End If
        admLogado = Session("AdmLogado")

        If IsPostBack = False Then
            tbnome.Text = admLogado.NomeAdm
            tbemail.Text = admLogado.EmailAdm
            tbsenha.Text = admLogado.SenhaAdm
        End If


    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Response.Redirect("~/Screens/WfPrincipalAdm.aspx")
    End Sub

    Public Sub enablebleTextbox()
        tbnome.Enabled = True
        tbemail.Enabled = True
        tbsenha.Enabled = True
    End Sub

    Public Sub desablebleTextbox()
        tbnome.Enabled = False
        tbemail.Enabled = False
        tbsenha.Enabled = False
    End Sub


    Protected Sub EditarSalvar_Click(sender As Object, e As EventArgs) Handles EditarSalvar.Click
        enablebleTextbox()
        atualizar.Visible = True
    End Sub

    Protected Sub atualizar_Click(sender As Object, e As EventArgs) Handles atualizar.Click
        Dim objAdmDao As New AdmDAO
        Dim objAdmAtualizado As New Adm
        Try
            objAdmAtualizado.CodAdm = admLogado.CodAdm
            objAdmAtualizado.NomeAdm = tbnome.Text.ToString
            objAdmAtualizado.EmailAdm = tbemail.Text.ToString
            objAdmAtualizado.SenhaAdm = tbsenha.Text.ToString
            objAdmDao.Atualizar(objAdmAtualizado)

            lbmsg.ForeColor = Drawing.Color.Blue
            lbmsg.Text = "Cadastro Atualizado com Sucesso !"
            EditarSalvar.Enabled = False
            desablebleTextbox()
            atualizar.Visible = False
            Session("AdmLogado") = objAdmAtualizado
        Catch ex As Exception
            lbmsg.ForeColor = Drawing.Color.Red
            lbmsg.Text = "Erro ao Atualizar Cadastro !"
        End Try
    End Sub

    Private Sub MeuCadastroAdm_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
        If Session("AdmLogado") Is Nothing Then
            Response.Redirect("/Screens/WF1.aspx")
        End If
    End Sub
End Class